package com.ghd.dataviz.constant;


import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 指标筛选枚举
 */
@Getter
@AllArgsConstructor
public enum KpiSelectorTypeEnum {
    EQ("eq", "="),
    NE("ne", "<>"),
    GT("gt", ">"),
    GE("ge", ">="),
    LT("lt", "<"),
    LE("le", "<="),
    ;

    @JsonValue
    private String code;
    private String desc;

    private static Map<String, KpiSelectorTypeEnum> map;

    static {
        map = Stream.of(KpiSelectorTypeEnum.values())
                .collect(Collectors.toMap(KpiSelectorTypeEnum::getCode, Function.identity(),
                        (k, v) -> k.ordinal() > v.ordinal() ? k : v ));
    }

    @JsonCreator
    public static KpiSelectorTypeEnum of(String code) {
        return map.get(code);
    }
}
